﻿using System;
using FlickrXplorer.Web.Objects;

namespace FlickrXplorer.Web.Plugin
{
  /// <summary>
  /// A base class for creating very simple FlickrXplorer plugins.
  /// </summary>
  /// <value>
  /// SidebarPlugin abstracts the low-level plugin creation logic
  /// away so that you can create a simple sidebar plugin in a
  /// \short time.
  /// </value>
  /// <example>
  /// This plugin displays &quot;Hello World!&quot; in the sidebar.
  /// 
  /// <code lang="c#">
  /// public class HelloWorldSidebarPlugin : SidebarPlugin
  /// {
  ///   public HelloWorldSidebarPlugin: base(&quot;Hello World Sidebar&quot;)
  ///   {
  ///   }
  /// 
  ///   protected override void OnLoad(PhotoData photoData)
  ///   {
  ///     this.Title = &quot;Hello World!&quot;;
  ///     this.Body = &quot;My first Sidebar plugin!&quot;;
  ///   }
  /// }
  /// </code>
  /// </example>                                                             
  public abstract class SidebarPlugin : FlickrXplorerPlugin
  {
    /// <summary>
    /// Gets or sets the Title of this Sidebar Plugin.
    /// </summary>                                    
    protected string Title { get; set; }
    /// <summary>
    /// Gets or Sets the Body of this Sidebar Plugin.
    /// </summary>                                   
    protected string Body { get; set; }

    /// <summary>
    /// Creates a new <see cref="FlickrXplorer.Web.Plugin.SidebarPlugin" text="SidebarPlugin" />
    /// instance and gives it a name.
    /// </summary>
    /// <param name="name">The name of the plugin.</param>                                      
    public SidebarPlugin(string name)
      : base(name)
    {
      this.LoadSideBar += new EventHandler<LoadSidebarEventArgs>(SimpleBasePlugin_LoadSideBar);
    }

    void SimpleBasePlugin_LoadSideBar(object sender, LoadSidebarEventArgs e)
    {
      // Tell the user to set his Title and Body
      OnLoad(e.PhotoData);

      // Create the output content
      string outputContent = String.Format(
        @"<div class='pTagBox'>
            <h2>{0}</h2>
            <div>
            <div style='display: inline; font-size: 18px;'> 
              {1}
            </div>
        </div>
      </div>", this.Title, this.Body);

      e.Content = outputContent;
    }

    /// <summary>
    /// Called when rendering the sidebar in Flickr Xplorer.
    /// </summary>
    /// <param name="photoData">Information about related
    ///                         photographs.</param>
    /// <see cref="FlickrXplorer.Web.Plugin.SidebarPlugin.Title" text="SidebarPlugin.Title Property" />
    /// 
    /// <see cref="FlickrXplorer.Web.Plugin.SidebarPlugin.Body" text="SidebarPlugin.Body Property" />
    ///                                                                                                
    protected abstract void OnLoad(PhotoData photoData);
  }
}
